﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace MN.Framework.Common
{
    public interface IColumnInfo
    {
        // Methods
        string FormatValue(object rawValue);
        string GetValue(object instance, string alternateColumnName = null);
        Type BaseType { get; set; }
        // Properties
        bool AllowFiltering { get; set; }
        bool AllowSorting { get; set; }
        int DefaultDisplayWidth { get; set; }
        string DefaultText { get; set; }
        //----MN-------
        string HeaderText { get; set; }
        bool ReadOnly { get; set; }

        string Name { get; set; }
        ColumnSize Size { get; set; }
        ColumnType Type { get; set; }
        bool Visible { get; set; }
        int Width(int smallWidth);
        int MaxLength { get; set; }
    }

    
    public abstract class ColumnInfo : IColumnInfo
    {
        // Fields
        private bool allowFiltering;
        private bool allowSorting;
        private string formatString;

        // Methods
        #region Method
        internal ColumnInfo()
        {
            this.allowSorting = true;
            this.allowFiltering = true;
            this.formatString = "";
        }
        public ColumnInfo(ColumnType columnType, Type type, string name, string headerText)
            : this()
        {
            this.Name = name;
            this.Type = columnType;
            this.HeaderText = headerText;
            this.BaseType = type;
            this.Size = ColumnSize.Standard;
        }
        public ColumnInfo(ColumnType columnType, Type type, string name, string headerText, ColumnSize size)
            : this(columnType, type, name, headerText)
        {
            this.Size = size;
        }
        public ColumnInfo(ColumnType type, string name, string defaultText, bool visible)
            : this()
        {
            this.Name = name;
            this.Type = type;
            this.DefaultText = defaultText;
            this.Visible = visible;
        }
        public ColumnInfo(ColumnType columnType, Type type, string name, string headerText, bool visible, bool readOnly)
            : this(columnType, type, name, headerText)
        {
            this.ReadOnly = readOnly;
            this.Visible = visible;
        }

        public override string ToString()
        {
            return string.Format("{0},{1},{2},{3}", new object[] { this.Name, this.Type, this.DefaultText, this.Visible });
        }
        #endregion
        // Properties
        #region Properties
        public virtual bool AllowFiltering
        {
            get
            {
                return this.allowFiltering;
            }
            set
            {
                this.allowFiltering = value;
            }
        }

        public virtual bool AllowSorting
        {
            get
            {
                return this.allowSorting;
            }
            set
            {
                this.allowSorting = value;
            }
        }

        public int DefaultDisplayWidth { get; set; }

        public string DefaultText { get; set; }

        public string HeaderText { get; set; }

        //public virtual string FormatString
        //{
        //    get
        //    {
        //        return this.formatString;
        //    }
        //    protected set
        //    {
        //        this.formatString = value;
        //    }
        //}

        public string Name { get; set; }

        public ColumnType Type { get; set; }

        public bool Visible { get; set; }

        public bool ReadOnly { get; set; }

        public Type BaseType { get; set; }

        public ColumnSize Size { set; get; }

        public int MaxLength { get; set; }
        #endregion
        
        public string FormatValue(object rawValue)
        {
            throw new NotImplementedException();
        }

        public string GetValue(object instance, string alternateColumnName = null)
        {
            throw new NotImplementedException();
        }

        public int Width(int smallWidth)
        {
            return (int)this.Size * smallWidth;
        }
    }

}
